package com.example.mvplibrary.adapter;

import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

/**
 * 项目名：p7_2_zong
 * 包名： com.example.mvplibrary.adapter
 * 文件名：MultipleAdapter
 * 创建者：朱勇闯
 * 创建时间：2021/3/18  15:47
 * 描述：TODO
 */
public class BaseViewHolder extends RecyclerView.ViewHolder {
    private View rootView;
    private SparseArray<View> sparseArray;

    public BaseViewHolder(View itemView) {
        super(itemView);
        rootView = itemView;
        sparseArray = new SparseArray<>();
    }

    //找控件
    public <T extends View> T getView(int viewId) {
        if (sparseArray.get(viewId) == null) {
            View viewById = rootView.findViewById(viewId);
            sparseArray.put(viewId, viewById);
        }
        return (T) sparseArray.get(viewId);
    }

    public void setText(int textViewId, String text) {
        TextView textView = getView(textViewId);
        textView.setText(text);
    }
    //    public void setImage(int ImageViewId, ImageView image){
//        ImageView textImage = getView(ImageViewId);
//
//    }
}
